package com.yt.user.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yt.common.constant.Result;
import com.yt.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.yt.user.models.service.ISysUserService;
import com.yt.user.models.bo.SysUserBO;
import com.yt.user.models.dto.SysUserDTO;

/**
 * 登录控制器
 *
 * @author xieyanfei
 * @Date 2025-09-05 18:01:35
 */

@RestController
@RequestMapping("/api/sysUser")
@Slf4j
@Api(value = "SysUserApiController",tags = "登录Api接口")
public class SysUserApiController {

    @DubboReference
    private ISysUserService sysUserService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysUserDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        SysUserDTO dto = sysUserService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "登录列表",notes = "登录列表")
    @PostMapping("/queryPageList")
    public Result<Page<SysUserDTO>> queryPageList(SysUserBO bo){
        Wrapper<SysUserDTO> wrapper = new EntityWrapper<>();
                if (bo.getStatus() != null){
                    wrapper.eq("status", bo.getStatus());
                }
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<SysUserDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = sysUserService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
